{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import json\n",
    "from keras.models import Model\n",
    "from keras.layers import Input\n",
    "from keras.layers.convolutional import Conv2D\n",
    "from keras.layers.pooling import MaxPooling2D, AveragePooling2D\n",
    "from keras.layers.normalization import BatchNormalization\n",
    "from keras import backend as K"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def format_decimal(arr, places=8):\n",
    "    return [round(x * 10**places) / 10**places for x in arr]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### pipeline 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'weights': [{'shape': [3, 3, 2, 5], 'data': [-0.41301916, -0.06548232, -0.27373104, 0.03463608, -0.45993658, 0.4865354, -0.19660301, -0.15413411, 0.07321166, 0.4660147, 0.03787414, 0.28148745, -0.48925452, 0.03053849, 0.46427825, -0.3340367, 0.49428242, -0.11228813, -0.37041425, -0.07633279, -0.42790588, 0.15693558, 0.49303097, 0.19876782, 0.04950603, 0.05806109, 0.08003724, 0.22830494, 0.49597338, -0.2804305, 0.42939438, 0.24273274, -0.45638821, -0.02349228, 0.17600165, 0.49173199, -0.45981763, -0.30585715, -0.0128569, -0.30422846, -0.35850094, 0.13143687, 0.33597551, -0.12145981, 0.08471007, -0.36319988, 0.11638593, 0.43377726, -0.0844127, -0.04048088, 0.41488413, -0.19283021, 0.31081145, -0.40510823, 0.39260834, -0.41011489, 0.40955659, 0.4535928, 0.4187157, 0.32875932, 0.3839722, -0.22723331, 0.39733175, 0.27852637, -0.46359521, 0.06622387, -0.1612151, -0.02176895, 0.07599637, -0.33743003, 0.38440459, 0.37484185, 0.29285209, -0.16604515, 0.26451534, 0.34501492, 0.36699692, -0.06173546, -0.1354522, -0.42280472, -0.0312215, 0.26075881, -0.02264135, -0.49086194, -0.14262083, 0.41873643, -0.07520476, -0.20732579, 0.39650289, -0.12683894]}, {'shape': [5], 'data': [0.36415093, 0.40228923, -0.41342038, 0.31929504, -0.17413196]}, {'shape': [5], 'data': [-0.45418954, -0.25829741, -0.07535405, -0.2309887, 0.36984941]}, {'shape': [5], 'data': [0.05203284, -0.2282396, -0.35603683, 0.1004984, 0.23607177]}, {'shape': [5], 'data': [-0.24926131, 0.02676308, 0.42653452, -0.42498293, 0.45429329]}, {'shape': [5], 'data': [0.23396634, 0.49746282, 0.41449719, 0.23837308, 0.10884336]}, {'shape': [3, 3, 5, 4], 'data': [-0.32984696, 0.47667503, 0.41403308, 0.03666963, -0.19412715, -0.24840993, -0.40496129, 0.03660749, 0.29243463, 0.29830495, 0.10882022, -0.09587598, -0.3183394, -0.18497127, 0.13730758, 0.32157827, -0.26656768, -0.46705981, 0.33862105, 0.11091295, 0.19265623, 0.37372817, 0.19199249, 0.02155339, 0.10171669, -0.4826839, 0.28003499, 0.37792047, 0.11955514, 0.22555801, 0.43038393, 0.00184438, -0.48824852, -0.19885654, 0.21829358, 0.18568121, -0.02327062, -0.36759491, -0.04478865, 0.11610227, 0.02350683, -0.26872255, 0.21650337, -0.12238978, 0.36748367, 0.15407914, 0.1833139, 0.41281641, 0.13005483, -0.22536095, -0.37669456, -0.18686398, 0.48098633, -0.123995, 0.16281004, 0.4997067, -0.33633231, 0.3298246, -0.15480855, 0.01605908, -0.42416607, 0.19373578, -0.15397204, 0.4133844, 0.09166544, -0.26641872, 0.43155853, 0.096551, 0.43605089, -0.35910366, 0.33532992, 0.37443155, -0.38333826, -0.01121068, -0.05620997, 0.21153868, 0.15370288, 0.28821034, -0.31319713, 0.30139598, -0.42570563, 0.43577762, -0.14749772, 0.23223807, 0.45626921, -0.02057325, -0.38266994, -0.33146502, 0.20948562, -0.18023638, 0.22777793, -0.4624728, 0.29732272, 0.08637754, 0.17760315, 0.40201963, -0.34451109, -0.43698252, -0.06942968, -0.01791114, 0.03190695, 0.06678995, -0.37920887, 0.33367153, 0.29843381, -0.34495439, 0.0754699, -0.20899213, -0.05651504, 0.39585042, -0.1309725, -0.05379819, 0.15665921, -0.34729283, 0.38109683, 0.35082446, 0.14603315, 0.19461494, 0.1979055, 0.05714051, 0.14534243, -0.00067989, -0.06555058, -0.23327284, -0.28780677, 0.2184984, -0.25476665, 0.33463066, -0.44992038, 0.43142554, -0.40677167, 0.10367638, -0.37280188, -0.29361127, 0.2491136, -0.28364498, -0.15834379, -0.03511265, -0.47800264, -0.35562599, 0.43660106, -0.21992596, -0.06738925, 0.04653624, -0.44014709, -0.03874882, -0.27221907, 0.25014181, -0.22596707, 0.3528869, 0.19415611, -0.15745483, -0.21340616, 0.07034828, -0.26263207, 0.41301672, -0.12015526, -0.24869657, -0.00723887, -0.45790538, -0.07566161, -0.12397337, -0.26520277, 0.1398717, 0.1955606, 0.44415327, -0.01972396, -0.22779471, 0.39357159, -0.37083373, 0.41529126, 0.00931896, -0.31345203, -0.04374553, 0.40463345, -0.20504796, -0.04813367, 0.08729579, 0.03945389, 0.16083067]}, {'shape': [4], 'data': [-0.09204122, 0.23119569, -0.49651266, 0.04577851]}, {'shape': [4], 'data': [-0.11027103, 0.13158462, 0.0246635, -0.03649735]}, {'shape': [4], 'data': [-0.49715631, 0.46995029, -0.00952293, 0.08436793]}, {'shape': [4], 'data': [-0.46930028, 0.19226734, -0.4448976, -0.31781987]}, {'shape': [4], 'data': [0.22643748, 0.26675454, 0.26990377, 0.24828169]}, {'shape': [3, 3, 4, 3], 'data': [-0.15640219, -0.02746415, 0.10527622, -0.47852924, 0.14125583, 0.36056272, -0.49911331, -0.41875285, 0.31040522, -0.31053001, 0.15627362, 0.01127547, -0.30663122, 0.32955299, 0.11102011, -0.31784038, 0.2954715, -0.299956, 0.17943158, -0.24261784, 0.46913432, -0.29917043, 0.00532614, -0.11720019, 0.22542166, -0.38746509, -0.2125259, -0.05629071, 0.27469078, 0.44000785, 0.06253906, -0.28611662, -0.15816073, 0.14902118, -0.06360207, 0.26361608, 0.36859329, 0.45594308, -0.42836989, -0.11290058, -0.49215642, -0.02135871, -0.43724358, 0.38777965, 0.19725203, 0.3625543, -0.19239383, 0.38672415, 0.31773277, -0.21655368, 0.10479253, 0.4903532, 0.09039112, -0.09628988, -0.41485567, 0.20733506, 0.23916592, -0.14443579, -0.21013391, 0.26205573, -0.04019815, -0.05424262, -0.07177221, 0.14218874, -0.18685103, -0.34189708, -0.12215504, -0.15872924, 0.05644055, -0.28076302, -0.44715451, 0.08351167, 0.48874677, 0.01870303, -0.42820514, 0.20610998, -0.37699391, 0.44920591, 0.39123808, -0.32348623, -0.24196254, -0.11526256, 0.14915693, -0.08671374, -0.09045303, 0.00417425, 0.15131685, -0.46018798, -0.16401771, -0.15217165, 0.10009151, 0.04688004, 0.08192027, -0.48553928, -0.25631688, 0.09676949, 0.4135524, -0.21019863, 0.33354406, -0.18350767, 0.03966393, 0.20965159, 0.26149962, 0.16654661, -0.30834802, 0.10279464, -0.3359057, -0.24036052]}, {'shape': [3], 'data': [-0.39532788, -0.32755898, 0.45650485]}, {'shape': [3], 'data': [0.08725845, 0.11414433, -0.27048277]}, {'shape': [3], 'data': [0.28123794, 0.14008539, 0.15848495]}, {'shape': [3], 'data': [-0.02361958, 0.09716654, 0.35439068]}, {'shape': [3], 'data': [0.24438752, 0.47677346, 0.45580899]}, {'shape': [3, 3, 3, 4], 'data': [0.38999223, -0.00485649, 0.30329345, 0.36825193, 0.38471301, -0.18783431, -0.20545727, 0.24651893, 0.20975408, -0.4582056, -0.30891728, 0.44113691, 0.39121796, 0.11693109, 0.39416235, 0.42192497, 0.42874912, -0.11300614, -0.26887847, 0.43652057, 0.2564509, 0.40008859, 0.29260048, -0.46160982, 0.15349586, -0.3691588, -0.17646493, 0.41222089, -0.41703288, 0.03910386, -0.30959991, 0.06491607, -0.07401101, 0.253842, 0.49244562, -0.44450396, -0.17429663, -0.13485832, 0.31062571, 0.46347555, 0.49596449, -0.24458812, 0.08500207, -0.28575837, -0.03996987, 0.42492438, 0.21273802, -0.49918088, -0.15511097, -0.29204409, 0.10028431, -0.1975815, -0.14379673, -0.01683905, 0.10978483, -0.40835883, 0.34302975, -0.10569794, -0.31769004, 0.06931692, -0.31241656, 0.27025811, -0.28674881, 0.03107318, -0.13468323, -0.32672691, -0.28409442, -0.04103884, -0.12246521, -0.04754089, -0.38565118, -0.25783654, -0.16888376, 0.14048922, 0.21463725, 0.16513464, -0.34763229, 0.34244006, 0.10064735, 0.24674537, 0.11763517, -0.09045559, -0.06253999, 0.28380461, -0.24170101, 0.35860588, 0.48693659, 0.47041505, -0.48009267, -0.13129122, -0.15329779, -0.32615339, -0.0288511, 0.48542069, -0.2435659, 0.32507247, -0.1235399, 0.09609411, 0.32152719, -0.41140514, -0.02451938, 0.15677153, -0.2816171, 0.14283823, -0.20214377, 0.08156554, -0.16343383, 0.28548783]}, {'shape': [4], 'data': [-0.11165831, -0.1079104, -0.21553367, 0.34881606]}, {'shape': [4], 'data': [0.23549706, -0.23226959, -0.30428747, 0.44306579]}, {'shape': [4], 'data': [-0.43370279, -0.46937641, 0.19772084, -0.12772498]}, {'shape': [4], 'data': [-0.46203008, -0.41492207, -0.06504652, -0.06781807]}, {'shape': [4], 'data': [0.31003341, 0.29014284, 0.35805159, 0.13118507]}, {'shape': [3, 3, 4, 2], 'data': [-0.40677367, 0.47586871, -0.04740775, -0.43232133, -0.1056076, 0.41150896, 0.07953007, 0.07919412, -0.3713563, 0.05691832, 0.47031414, 0.00942043, 0.1602868, 0.26178192, 0.46296194, -0.03144408, -0.11952705, 0.26681484, -0.05300264, 0.16774379, 0.12129931, 0.23723094, -0.11353842, 0.49640083, 0.21749213, -0.05203755, 0.15573911, -0.29284554, -0.07625518, 0.42209938, -0.23366962, -0.47133622, -0.22970858, -0.44600847, -0.3093829, -0.4121238, -0.14138566, -0.20441095, 0.39614968, -0.20126133, -0.10797807, -0.42581485, -0.05478691, -0.04565391, 0.02821994, -0.09418995, 0.16077138, 0.00968192, 0.35454778, 0.17358882, 0.26811062, 0.08160452, -0.38545712, -0.19653542, -0.24515864, 0.40234098, 0.32753208, -0.01400066, -0.45171829, 0.46315238, 0.0712278, 0.41641071, 0.43632559, 0.00098648, -0.18226762, -0.33641785, -0.27264541, 0.22226361, 0.3570469, 0.21814369, 0.1184784, 0.21969704]}, {'shape': [2], 'data': [0.23469275, -0.10722625]}, {'shape': [2], 'data': [-0.27970142, -0.05953101]}, {'shape': [2], 'data': [-0.24626762, 0.13961548]}, {'shape': [2], 'data': [-0.40271084, -0.46918207]}, {'shape': [2], 'data': [0.38538645, 0.37367422]}], 'input': {'shape': [24, 24, 2], 'data': [-0.82603833, -0.13096464, -0.54746208, 0.06927216, -0.91987316, 0.9730708, -0.39320602, -0.30826822, 0.14642331, 0.9320294, 0.07574828, 0.5629749, -0.97850904, 0.06107697, 0.9285565, -0.6680734, 0.98856484, -0.22457627, -0.7408285, -0.15266559, -0.85581175, 0.31387115, 0.98606195, 0.39753564, 0.09901205, 0.11612217, 0.16007448, 0.45660988, 0.99194675, -0.560861, 0.85878876, 0.48546548, -0.91277642, -0.04698456, 0.3520033, 0.98346397, -0.91963525, -0.6117143, -0.02571379, -0.60845692, -0.71700187, 0.26287375, 0.67195102, -0.24291961, 0.16942015, -0.72639976, 0.23277185, 0.86755452, -0.1688254, -0.08096177, 0.82976826, -0.38566042, 0.62162291, -0.81021647, 0.78521669, -0.82022978, 0.81911317, 0.90718561, 0.83743139, 0.65751865, 0.7679444, -0.45446663, 0.79466351, 0.55705274, -0.92719041, 0.13244773, -0.3224302, -0.04353791, 0.15199274, -0.67486006, 0.76880917, 0.7496837, 0.58570417, -0.3320903, 0.52903069, 0.69002984, 0.73399383, -0.12347092, -0.2709044, -0.84560945, -0.062443, 0.52151761, -0.04528269, -0.98172388, -0.28524167, 0.83747286, -0.15040952, -0.41465158, 0.79300578, -0.25367788, -0.86961993, -0.7143939, 0.75972198, 0.23964349, 0.69206169, 0.24932983, 0.43020974, 0.99294004, -0.63022653, -0.77898226, -0.99050229, 0.95949654, -0.35682611, 0.68640556, -0.26578804, 0.82510516, -0.73237143, -0.11305386, -0.10993288, -0.63776461, 0.38332089, 0.16795156, -0.56626847, 0.76241806, 0.00333043, 0.28228024, 0.56378468, -0.5839801, -0.54105223, 0.30544327, 0.3724745, -0.645694, 0.00805129, -0.63550558, -0.06388475, -0.47078536, -0.068132, 0.5045015, 0.7449024, 0.96200228, 0.8100647, -0.3685048, -0.82160738, 0.39196063, -0.03074081, 0.793353, 0.37199876, 0.73180589, -0.10536613, -0.01370263, -0.31972425, -0.20730178, -0.48132496, -0.18478201, -0.46630919, -0.96893619, 0.62810221, -0.55108253, 0.48101722, 0.60366761, 0.3606246, -0.50902873, 0.02111305, -0.6288284, -0.37492558, 0.30647775, 0.24823465, -0.06566859, 0.30705072, -0.29182136, -0.93374464, 0.29532748, -0.53001332, 0.92699088, 0.31875421, 0.78281256, -0.34067166, -0.54086865, 0.87904323, -0.96473892, 0.26631592, -0.26393781, 0.75552184, -0.23799586, -0.190742, 0.2874423, -0.55036338, 0.38108647, 0.84253313, 0.00976179, 0.75384451, -0.77374152, -0.68553518, -0.18241331, -0.66075321, 0.37103012, 0.4021849, 0.65882469, -0.71071108, 0.76073393, -0.6380888, 0.26318094, -0.10682218, 0.77856505, 0.89038816, -0.62462272, -0.26178805, -0.89349034, 0.84342388, 0.70538743, -0.44505846, 0.67926814, -0.03573406, 0.12521276, -0.42370387, -0.77026185, 0.05310233, 0.00490482, -0.60078811, -0.91795913, 0.03009541, -0.72178911, 0.8331429, -0.87376786, -0.44822928, -0.09279648, 0.18152921, -0.83407492, 0.94921531, 0.11416123, 0.62560045, 0.19067556, -0.23717171, 0.89499579, 0.55731076, -0.78463088, -0.04329275, 0.27290336, -0.57591831, -0.07864426, 0.3238054, -0.11181014, 0.19369645, -0.47850106, -0.0056769, -0.95955339, 0.17458301, -0.83217416, 0.18414615, -0.56258265, -0.81400352, 0.12795238, 0.39143404, 0.13993307, -0.93289893, 0.87874544, 0.28062293, 0.79291684, -0.72086271, 0.55297382, -0.55425301, 0.40460552, 0.62111079, 0.30789674, -0.14145143, 0.55103305, 0.69114205, 0.39010925, -0.47054084, 0.34825716, 0.00790379, 0.66557139, -0.01250755, 0.62228883, -0.4217995, 0.70211475, -0.71172108, -0.65377351, 0.86850315, -0.38760257, 0.34950285, 0.84827493, 0.72667616, 0.23475093, -0.55850182, -0.04782195, 0.99432862, 0.40933945, 0.06120931, -0.59961316, -0.19507317, -0.40294719, 0.55828879, 0.34338436, -0.07474555, -0.16917446, -0.01610377, 0.76300856, -0.51591773, -0.02524371, -0.1636733, 0.37381786, -0.75886949, -0.88332428, -0.07399728, -0.00169522, 0.79422446, 0.84192834, 0.53851786, 0.16053535, 0.73630846, 0.11855384, -0.48726972, 0.15607844, -0.83207867, 0.86342299, 0.28832868, -0.81971701, 0.06852399, -0.11409834, 0.98519521, 0.07238126, 0.73708715, 0.61618635, 0.62653754, 0.73869941, 0.35459732, 0.68986115, -0.34380559, 0.20693211, -0.10619374, -0.75911849, -0.38429728, 0.10754408, 0.04697893, 0.30756016, 0.13514621, -0.64676487, -0.53255601, -0.80009673, 0.20167486, 0.46575034, 0.08572316, 0.46988287, -0.05069229, 0.00790549, 0.01003173, 0.80044435, 0.83161943, -0.0995879, 0.06782259, 0.95275963, -0.58178434, -0.29582562, -0.73594229, -0.40683332, -0.35507954, -0.92663419, 0.68726858, -0.00478801, 0.64322765, 0.78332288, 0.54804598, 0.61862293, -0.50287124, 0.83402948, -0.87334377, -0.55930962, 0.1367568, 0.06703942, -0.51506208, 0.48165814, 0.42230724, -0.14477578, 0.46297352, -0.61743724, -0.04857921, 0.66421417, 0.04923253, -0.35587259, -0.35986345, -0.86597937, -0.40701032, -0.66532125, 0.35734985, 0.03880887, 0.93282328, 0.79100709, 0.48832435, 0.87330014, 0.49496435, -0.82950106, -0.35691117, 0.84154154, -0.87181414, -0.31886679, 0.27827334, 0.60510102, -0.34856963, 0.07848324, 0.20327735, 0.32794064, -0.77191, 0.8359221, -0.340859, -0.70935903, 0.1829014, 0.290669, 0.92097964, -0.03551396, -0.08815947, 0.6248324, 0.85322848, -0.05680283, -0.35498452, -0.51160877, -0.48412745, -0.41585824, 0.93606416, 0.90993218, -0.26116773, 0.98782053, 0.05354171, -0.04971585, 0.19934791, 0.00790815, 0.5840446, -0.04660718, -0.31621629, -0.43157719, 0.35139426, 0.25419153, -0.40485577, -0.81625849, 0.21739551, -0.62730134, 0.00575841, 0.23016077, 0.11121829, 0.12147199, -0.79856242, 0.52442687, 0.85226082, -0.47467447, 0.00286789, 0.37495641, 0.57664407, 0.90916639, -0.57075077, -0.61669158, -0.8208092, 0.71475094, -0.43899087, 0.10104882, -0.30294957, -0.71606867, -0.2370588, -0.97103893, 0.59202193, 0.97658706, 0.99963381, -0.46818823, -0.37262552, -0.17314187, -0.98991569, -0.3114812, 0.29877849, -0.53053618, 0.91759399, -0.64692173, 0.09372522, 0.60024931, -0.97186711, 0.10888726, -0.6895695, -0.49322987, -0.97871603, 0.87155414, 0.09843955, 0.96114316, 0.04514516, 0.86212483, 0.73173911, 0.02284462, 0.37366816, -0.32910703, 0.50406217, 0.05396065, -0.5660752, 0.66071206, -0.66239177, -0.68623549, -0.43751792, 0.92579925, -0.70815038, -0.22657949, 0.06296668, -0.50893131, 0.96504696, 0.78351318, 0.32183006, 0.06762182, 0.95266734, -0.26770906, -0.21396114, -0.04908317, -0.58700135, 0.85777008, 0.30586169, -0.46163604, -0.92361962, -0.8176457, -0.13309356, 0.78253851, 0.12727106, 0.68954939, -0.29049454, -0.19219861, 0.70180787, -0.15084912, -0.44430616, -0.72686682, -0.76822832, -0.38998231, 0.91181968, -0.94000668, -0.80786118, -0.74724433, -0.67849463, 0.49841497, -0.74729604, 0.26693091, 0.86274158, -0.80427631, 0.90163215, 0.04029213, 0.91953834, 0.85452004, -0.97872434, -0.43619111, 0.13044651, 0.05209664, -0.3972997, 0.2037326, 0.46427822, -0.63308285, 0.8114176, -0.79276233, -0.80430869, -0.55430841, 0.67925045, -0.98282878, -0.42862075, 0.76944815, 0.6064559, 0.04159172, -0.46833065, -0.86472583, 0.15220931, -0.1401678, 0.28490795, 0.73087149, -0.71371328, -0.47345478, 0.93889122, 0.75238704, 0.64786561, 0.77617311, -0.73821932, -0.42940018, -0.70112985, -0.1632199, -0.52774687, -0.21229779, 0.40157296, -0.17086508, 0.92556426, -0.2850343, 0.3530399, -0.50955094, -0.37181431, 0.72745507, 0.1413673, 0.30159895, 0.14603869, -0.78887043, 0.02456768, -0.97064044, 0.37356868, -0.7253777, -0.52076616, -0.4167877, 0.88898708, 0.31434094, 0.66059931, -0.1054491, -0.54194941, -0.57562137, -0.09962318, -0.37069404, 0.21186834, 0.61617885, 0.40315778, -0.43317843, 0.89497702, 0.74787274, 0.31838641, 0.25640876, -0.41844552, 0.6275263, -0.81701332, -0.68878508, -0.46419624, -0.66110007, -0.46598949, -0.97263863, 0.47370482, 0.44774142, 0.6692852, 0.63301705, 0.08513352, 0.90048893, -0.75943322, -0.31023123, -0.54797572, 0.60214546, 0.64228981, -0.642168, -0.97409273, -0.99066582, 0.34107397, -0.27939802, 0.16156164, 0.95290724, 0.72840182, -0.73146947, -0.29344182, 0.17185604, -0.11162506, -0.928958, -0.7281772, 0.24879728, -0.65555855, 0.48892074, 0.40779497, -0.10581159, -0.99360314, -0.43798163, -0.27816046, 0.05284592, -0.94713651, -0.24960637, -0.24948098, -0.63654652, 0.79529038, -0.94162159, 0.47851524, -0.49005876, 0.57984938, 0.92650678, -0.08794787, -0.68986886, 0.99151895, -0.72133188, -0.3123501, 0.74190322, -0.77461026, 0.45796329, -0.57644306, -0.8397129, -0.13002605, -0.34632534, -0.19551361, -0.85147512, 0.61675052, -0.47599913, 0.72025297, -0.43688073, -0.16667027, -0.37606361, 0.77684494, 0.11253284, -0.60134021, 0.57759153, -0.36555101, -0.76343796, 0.70818167, 0.48443241, -0.34127767, -0.16099768, 0.3263443, -0.48168595, -0.06365813, 0.51478172, 0.0335012, -0.32519089, -0.17412401, -0.55017408, 0.32794919, -0.7012895, 0.87668184, -0.69384138, 0.5147139, 0.07282544, 0.48248023, 0.49865562, -0.77606146, 0.78551031, -0.70860069, -0.04933939, -0.61242246, 0.31346362, -0.27041372, -0.61158729, 0.88682417, 0.43041756, 0.57639414, 0.63676516, 0.76406892, 0.3753746, 0.96164559, 0.13188882, -0.04675627, 0.87951116, 0.79278089, 0.09452128, 0.42095302, 0.42331606, -0.65789989, 0.52789602, -0.78803846, -0.99966373, 0.92696635, 0.96302853, 0.11880799, -0.47039306, 0.94981809, -0.48549904, -0.79987695, -0.29760038, -0.55163387, 0.20348608, -0.19601682, 0.3951984, 0.28235468, -0.58349366, -0.84479326, -0.67387493, 0.66122699, -0.97895066, -0.01624241, -0.97843628, -0.45031033, -0.18230258, 0.00594667, 0.17949129, 0.03720607, 0.65333631, -0.60325757, -0.68567796, -0.2890286, 0.22142224, 0.72091349, 0.39768661, -0.4188249, -0.18257646, -0.80993503, -0.0551552, 0.28611555, 0.46437853, -0.16351689, -0.3229502, -0.73744834, 0.5455045, 0.15948346, -0.45445168, -0.39791366, 0.49459222, -0.29347796, -0.371366, -0.13394278, -0.23114653, -0.82749368, -0.19870463, 0.29428287, 0.90579806, -0.42516196, 0.90793803, 0.975542, 0.90337827, -0.59775418, 0.76408764, -0.14950906, -0.01373453, -0.76994099, 0.16468887, -0.97926104, -0.23849418, -0.72386133, 0.84639151, -0.30958268, 0.61045685, -0.54263275, 0.98414904, 0.450509, 0.70410507, 0.3436203, 0.39440044, -0.00284086, -0.09657835, -0.54912787, 0.54213639, -0.91664145, 0.79060274, -0.60428595, 0.64932362, -0.55256733, 0.35881804, -0.55316788, 0.46395104, 0.93994266, -0.69152194, -0.55352526, 0.14072547, 0.98304054, 0.63807915, -0.51144115, 0.57271058, 0.61731406, -0.41591733, 0.09592848, 0.75056662, 0.25621165, 0.61720275, -0.31380824, -0.22274306, -0.43706214, -0.94416585, 0.4324897, -0.40000183, 0.77437671, -0.05198882, -0.65829181, 0.02421801, 0.0815735, 0.80616693, -0.18483535, -0.57535407, -0.10983156, 0.62431378, 0.12963698, 0.67555769, -0.09629461, 0.52611463, 0.33241578, -0.01016324, -0.0680069, -0.45452804, -0.12916927, 0.17379373, -0.82926423, -0.12954161, 0.30690532, 0.84708617, 0.32285889, 0.14720782, 0.17996479, 0.88661989, -0.78028994, -0.13587125, 0.63703576, -0.97170985, -0.16898291, 0.3470872, -0.21297267, 0.9794218, 0.45299194, -0.33859128, 0.56459432, -0.45694667, -0.29233799, -0.64214237, -0.83508777, -0.4884001, -0.67657286, -0.15257206, -0.50981246, -0.19491886, 0.9934169, 0.74814942, -0.38347909, 0.34603462, 0.33034796, -0.42000893, 0.17798984, 0.93675125, 0.26206101, -0.20979034, -0.99770511, 0.88287631, 0.47800299, 0.81673298, -0.45042436, -0.24825374, -0.3183967, 0.09516295, -0.65549842, 0.18031854, -0.44332453, 0.17965435, -0.26986997, 0.87244592, -0.18583517, 0.60598198, -0.85484798, 0.87947657, -0.70507408, 0.2763704, -0.98232885, 0.46066041, -0.61570766, 0.23972579, 0.3742597, -0.44732814, -0.2564419, -0.20208596, -0.34391833, -0.4745966, -0.43068835, -0.25450671, 0.6113527, -0.84089297, -0.25401281, -0.00936695, 0.84432887, 0.59374823, -0.97268183, 0.62442069, -0.72186775, -0.06727134, 0.58831368, -0.27483071, -0.78850385, 0.05505796, 0.59665485, -0.0432563, -0.73422372, 0.9114502, -0.44814538, -0.87606376, -0.78105927, -0.48462925, 0.77052814, 0.42939269, 0.71650587, -0.17078479, -0.22877736, -0.53788601, -0.05752285, -0.56406667, 0.77380201, -0.43546576, -0.60699587, 0.63716112, 0.41354209, 0.99668071, -0.40065768, 0.72319371, -0.75842286, 0.7562754, 0.38802236, -0.56224889, -0.47556502, 0.08826268, -0.73156864, 0.06266839, -0.16488875, -0.66147052, 0.79997358, -0.60075262, 0.65577625, -0.49855946, -0.39359605, -0.49393347, -0.09016229, 0.18656243, 0.60341061, 0.56537163, -0.07369294, 0.58825432, -0.09382222, 0.41011131, 0.97200283, 0.85093461, 0.32159828, 0.67608332, -0.31222369, 0.79253055, 0.46032151, 0.48142789, 0.87327207, 0.46833658, -0.5584723, 0.76603477, 0.97678253, 0.01528128, 0.83877172, 0.38431356, -0.22805101, -0.22351683, 0.44111894, -0.49345637, -0.46367623, -0.73179044, 0.22700461, 0.50533759, 0.4838265, -0.43724024, 0.97715973, -0.44745182, -0.14855094, 0.67320144, 0.2353737, 0.72608404, 0.87912242, -0.112663, -0.18336504, 0.90462021, 0.33355815, 0.10967073, -0.31873185, -0.56696899, 0.8172631, 0.80435686, 0.14743914, 0.65475306, 0.26523191, 0.02262875, -0.46316707, 0.0134135, -0.30335847, 0.31684352, -0.00986265, -0.28692807, -0.03733324, -0.2560267, -0.8879127, 0.04243062, 0.97186426, -0.46314339, -0.27426642, 0.450112, 0.2864991, 0.93572986, 0.00209061, -0.54393344, -0.61655051, 0.10972604, 0.18845884, 0.4045002, -0.4525549, 0.80459949, 0.96196072, -0.92142522, 0.12627213, -0.9018517, 0.96332191, -0.79386124, -0.99905024, -0.12894161, 0.33744022, -0.25064722, -0.64959701, -0.07689778, -0.55339333, -0.69249379, 0.43061933, -0.80536806, -0.51879168, 0.34574073, -0.72090303, -0.63374439, 0.80451826, 0.41393262, 0.97379709, -0.57895503, -0.73915427, 0.6737996, 0.68883576, -0.56470176, -0.42810125, -0.24823211, 0.62394168, -0.19126338, 0.47085511, -0.34365487, 0.91524969, 0.6255311, 0.25095381, -0.9823589, 0.70994743, -0.20257635, -0.11653914, -0.51498191, -0.15030402, -0.77526879, 0.40534996, 0.3313457, 0.47204681, -0.82145351, 0.42543606, -0.90171958, 0.03443627, -0.26339692, 0.41487262, 0.12954197, 0.16541129, 0.47539047, 0.43403193, -0.49353984, 0.83407137, -0.81255179, 0.46812387, 0.47295565, -0.17013796, 0.84897978, -0.17299331, 0.61865334, 0.26604814, 0.98319564, 0.00888366, 0.70878429, -0.08634435, -0.68167581, 0.6814779, -0.87846374, -0.67810693, 0.51097247, 0.85375437, -0.47049519, -0.3370149, 0.03683555, 0.20874076, -0.46373424, -0.35484567, -0.68557246, -0.23030547, -0.22318676, -0.26829927, -0.08639185, 0.25801868, -0.12501729, 0.37867492, 0.04590355, -0.46139934, 0.63055799, -0.84571702, 0.65960319, 0.31657999, -0.18741285, 0.11709874, -0.48004723]}, 'expected': {'shape': [1, 1, 2], 'data': [-1.23473299, 0.05060276]}}\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (24, 24, 2)\n",
    "\n",
    "conv_0 = Conv2D(5, 3, 3, activation='relu', border_mode='valid', subsample=(2, 2), dim_ordering='tf', bias=True)\n",
    "bn_0 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "conv_1 = Conv2D(4, 3, 3, activation='relu', border_mode='same', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_1 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "conv_2 = Conv2D(3, 3, 3, activation='relu', border_mode='same', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_2 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "pool_0 = AveragePooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='tf')\n",
    "conv_3 = Conv2D(4, 3, 3, activation='linear', border_mode='valid', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_3 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "conv_4 = Conv2D(2, 3, 3, activation='relu', border_mode='same', subsample=(1, 1), dim_ordering='tf', bias=True)\n",
    "bn_4 = BatchNormalization(mode=0, axis=-1, epsilon=1e-3)\n",
    "pool_1 = AveragePooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='tf')\n",
    "\n",
    "input_layer = Input(shape=data_in_shape)\n",
    "x = conv_0(input_layer)\n",
    "x = bn_0(x)\n",
    "x = conv_1(x)\n",
    "x = bn_1(x)\n",
    "x = conv_2(x)\n",
    "x = bn_2(x)\n",
    "x = pool_0(x)\n",
    "x = conv_3(x)\n",
    "x = bn_3(x)\n",
    "x = conv_4(x)\n",
    "x = bn_4(x)\n",
    "output_layer = pool_1(x)\n",
    "model = Model(input=input_layer, output=output_layer)\n",
    "\n",
    "np.random.seed(11000)\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(11000 + i)\n",
    "    if i % 6 == 5:\n",
    "        # std should be positive\n",
    "        weights.append(0.5 * np.random.random(w.shape))\n",
    "    else:\n",
    "        weights.append(np.random.random(w.shape) - 0.5)\n",
    "model.set_weights(weights)\n",
    "\n",
    "result = model.predict(np.array([data_in]))\n",
    "\n",
    "print({\n",
    "    'input': {'data': format_decimal(data_in.ravel().tolist()), 'shape': list(data_in_shape)},\n",
    "    'weights': [{'data': format_decimal(weights[i].ravel().tolist()), 'shape': list(weights[i].shape)} for i in range(len(weights))],\n",
    "    'expected': {'data': format_decimal(result[0].ravel().tolist()), 'shape': list(result[0].shape)}\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
